Skip to content

feat(gitea): implement GetTaskURI for remote task resolution#2732

Draft
theakshaypant wants to merge 1 commit into
tektoncd:mainfrom
theakshaypant:forgejo/get-task-uri
Draft

feat(gitea): implement GetTaskURI for remote task resolution#2732
theakshaypant wants to merge 1 commit into
tektoncd:mainfrom
theakshaypant:forgejo/get-task-uri

Conversation

@theakshaypant
Copy link
Copy Markdown
Member

📝 Description of the Change

Enable Gitea/Forgejo provider to resolve remote taskRef URLs using the provider's authenticated API instead of returning "not supported". Supports branch, tag, and commit SHA URL formats.

🔗 Linked GitHub Issue

N/A

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests - TODO
  • Manual testing
  • Not Applicable

🤖 AI Assistance

AI assistance can be used for various tasks, such as code generation,
documentation, or testing.

Please indicate whether you have used AI assistance
for this PR and provide details if applicable.

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Important

Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Claude noreply@anthropic.com

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

Enable Gitea/Forgejo provider to resolve remote taskRef URLs using
the provider's authenticated API instead of returning "not
supported". Supports branch, tag, and commit SHA URL formats.

Signed-off-by: Akshay Pant <akpant@redhat.com>
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements the GetTaskURI method for the Gitea provider, enabling the retrieval of task files from Gitea and Forgejo URLs. It introduces a splitGiteaURL helper function to extract organization, repository, reference, and path information, supported by new unit tests. Review feedback highlights the need for more robust URL handling by using EscapedPath and PathUnescape to correctly process encoded characters like slashes and plus signs. Additionally, it is recommended to verify the Gitea client's initialization to prevent potential nil pointer panics.

Comment on lines +159 to +162
uriPath := pURL.Path
if pURL.RawPath != "" {
uriPath = pURL.RawPath
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using pURL.Path for splitting is problematic because it is already unescaped by url.Parse. If a path segment (such as a branch name or a directory) contains an encoded slash (%2F), pURL.Path will contain a literal /, causing strings.Split to break the segment incorrectly. Using pURL.EscapedPath() ensures you split only on the intended delimiters.

Suggested change
uriPath := pURL.Path
if pURL.RawPath != "" {
uriPath = pURL.RawPath
}
uriPath := pURL.EscapedPath()

Comment on lines +184 to +195
if spRef, err = url.QueryUnescape(spRef); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode ref: %w", err)
}
if spPath, err = url.QueryUnescape(spPath); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode path: %w", err)
}
if spOrg, err = url.QueryUnescape(spOrg); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode org: %w", err)
}
if spRepo, err = url.QueryUnescape(spRepo); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode repo: %w", err)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When decoding path segments, url.PathUnescape should be used instead of url.QueryUnescape. QueryUnescape incorrectly treats + as a space, which is not the case for URL path segments. Additionally, since the path is now extracted using EscapedPath(), all segments must be explicitly unescaped to restore their original values.

Suggested change
if spRef, err = url.QueryUnescape(spRef); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode ref: %w", err)
}
if spPath, err = url.QueryUnescape(spPath); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode path: %w", err)
}
if spOrg, err = url.QueryUnescape(spOrg); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode org: %w", err)
}
if spRepo, err = url.QueryUnescape(spRepo); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode repo: %w", err)
}
if spRef, err = url.PathUnescape(spRef); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode ref: %w", err)
}
if spPath, err = url.PathUnescape(spPath); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode path: %w", err)
}
if spOrg, err = url.PathUnescape(spOrg); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode org: %w", err)
}
if spRepo, err = url.PathUnescape(spRepo); err != nil {
return "", "", "", "", fmt.Errorf("cannot decode repo: %w", err)
}

Comment on lines +210 to +214
data, _, err := v.Client().GetFile(spOrg, spRepo, spRef, spPath)
if err != nil {
return false, "", err
}
return true, string(data), nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The v.Client() call returns the underlying Gitea client. If the client has not been initialized, this call will return nil, leading to a panic. According to the repository's rules on lazy initialization, the Client() method should be implemented to return a new instance directly if the internal field is nil, rather than returning nil and requiring the caller to handle the error. This avoids potential panics and ensures thread safety for stateless or lightweight objects.

Suggested change
data, _, err := v.Client().GetFile(spOrg, spRepo, spRef, spPath)
if err != nil {
return false, "", err
}
return true, string(data), nil
client := v.Client()
if client == nil {
return false, "", fmt.Errorf("no gitea client has been initialized")
}
data, _, err := client.GetFile(spOrg, spRepo, spRef, spPath)
if err != nil {
return false, "", err
}
return true, string(data), nil
References
  1. Avoid lazy initialization of stateless and lightweight objects without proper synchronization. Instead, return a new instance directly if the field is nil.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 66.66667% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.38%. Comparing base (f05bcd0) to head (8c9bdc4).

Files with missing lines Patch % Lines
pkg/provider/gitea/gitea.go 66.66% 12 Missing and 6 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2732      +/-   ##
==========================================
+ Coverage   59.36%   59.38%   +0.02%     
==========================================
  Files         208      208              
  Lines       20626    20678      +52     
==========================================
+ Hits        12244    12280      +36     
- Misses       7610     7620      +10     
- Partials      772      778       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants